#ifndef LOG_LOGFORMAT_H
#define LOG_LOGFORMAT_H

#include "utility/Noncopyable.h"
#include "utility/type.h"

#include <array>
#include <cstdio>

class Logformat final {
public:
    template<typename T> Logformat(const char *fmt, T t);
    ~Logformat() = default;

    const char *data() const { return _buffer.data(); }
    int length() const { return _length; }

private:
    NONCOPYABLE(Logformat);

    static constexpr auto _BUFFER_SIZE = 1 << 5;

    std::array<char, _BUFFER_SIZE> _buffer;
    const int _length;
};

template<typename T>
Logformat::Logformat(const char *fmt, T t):
    _buffer{},
    _length{
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
        ::snprintf(_buffer.data(), _BUFFER_SIZE, fmt, t)
#ifdef __clang__
#pragma clang diagnostic pop
#endif
    } {
        STATIC_ASSERT_ARITHMETIC(T);
}



#endif